//
//  JTTakeAlbumOrCamera.m
//  Together
//
//  Created by rimi on 16/7/12.
//  Copyright © 2016年 Zjq. All rights reserved.
//

#import "JTTakeAlbumOrCamera.h"
@interface JTTakeAlbumOrCamera () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@end

@implementation JTTakeAlbumOrCamera
#pragma mark - 打开相册
+ (void)takeAlbumWithViewcontroller:(UIViewController*)viewcontroller withID:(id)delegate{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.delegate = delegate;
    imagePicker.allowsEditing = YES;
    [viewcontroller presentViewController:imagePicker animated:YES completion:nil];
}

#pragma mark - 打开相机
+ (void)takeCameraWithViewcontroller:(UIViewController*)viewcontroller withID:(id)delegate{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
        if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {
            UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
            imagePicker.delegate = delegate;
            imagePicker.allowsEditing = YES;
            imagePicker.sourceType = sourceType;
            [viewcontroller presentViewController:imagePicker animated:YES completion:nil];
        }else{
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"检查拍照功能" preferredStyle:UIAlertControllerStyleAlert ];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
            [alertController addAction:cancelAction];
            [viewcontroller presentViewController:alertController animated:YES completion:nil];
        }
}

@end
